package cn.sczhyt.modules.szhy.controller;

import java.util.Arrays;

import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.R;
import cn.sczhyt.common.utils.UploadFileUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.sczhyt.modules.szhy.entity.MeetingEntity;
import cn.sczhyt.modules.szhy.service.MeetingService;
import org.springframework.web.multipart.MultipartFile;

import static cn.sczhyt.common.utils.ShiroUtils.getUserId;
import static cn.sczhyt.common.utils.ShiroUtils.getUsername;


/**
 * 会议基本信息表
 *
 * @author luoshijie
 * @email 1169414426@qq.com
 * @date 2020-09-03 10:22:11
 */
@Api(tags = "PC端会议管理")
@RestController
@RequestMapping("szhy/meeting")
public class MeetingController {
    @Autowired
    private MeetingService meetingService;
    /**
     * 列表
     */
    @ApiOperation("列表")
    @PostMapping("/list")
    public R list(@RequestParam(defaultValue = "1") Integer page,
                   @RequestParam(defaultValue = "20") Integer limit,
                   @RequestBody(required = false) MeetingEntity meetingEntity) {
        String userId = getUserId();
        IPage<MeetingEntity> iPage = meetingService.findList(page, limit, userId,meetingEntity);
        PageUtils pages = new PageUtils(iPage);
        return R.ok().put("data", pages);
    }
//    /**
//     * 已发布列表
//     */
//    @PostMapping("/list1")
//    @RequiresPermissions("szhy:meeting:list1")
//    public R list1(@RequestParam Integer page, @RequestParam Integer limit, @RequestBody MeetingEntity meetingEntity){
//
//        IPage<MeetingEntity> iPage = meetingService.findList(page,limit,meetingEntity);
//
//        PageUtils pages=new PageUtils(iPage);
//        return R.ok().put("data", pages);
//    }
    /**
     * 信息
     */
    @ApiOperation("会议信息")
    @GetMapping("/info/{meetingId}")
    public R info(@PathVariable("meetingId") String meetingId) {

        MeetingEntity meeting = meetingService.getById(meetingId);

        return R.ok().put("meeting", meeting);
    }


    /**
     * 会议基本信息保存,修改
     */
    @ApiOperation("会议保存或修改")
    @PostMapping("/save")
    public R save(@RequestBody MeetingEntity meeting) {

        String meetingCreateId = getUserId();
        String meetingCreateName = getUsername();
        meeting.setMeetingCreateId(meetingCreateId);
        meeting.setMeetingCreateName(meetingCreateName);
        meetingService.meetingSave(meeting);

        return R.ok();
    }
    /**
     * 删除
     */
    @ApiOperation("会议删除")
    @PostMapping("/delete")
    //@RequiresPermissions("szhy:meeting:delete")
    public R delete(@RequestBody String[] ids) {
        meetingService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
